package com.javasm.service.impl;

import com.javasm.dao.DynamicsDao;
import com.javasm.entity.Dynamics;
import com.javasm.service.DynamicsService;
import com.javasm.utils.MyBatisHeapler;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class DynamicsServiceImpl implements DynamicsService {
    @Override
    public int countCustomerDynamics(Dynamics inputDynamics) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        int count = sqlSession.getMapper(DynamicsDao.class).countCustomerDynamics(inputDynamics);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return count;
    }

    @Override
    public int deleteCustomerDynamics(Dynamics inputDynamics) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        int resNum = sqlSession.getMapper(DynamicsDao.class).deleteCustomerDynamics(inputDynamics);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }

    @Override
    public List<Dynamics> listCustomerDynamics(Dynamics inputDynamics, Integer page, Integer pageSize) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        List<Dynamics> dynamics = sqlSession.getMapper(DynamicsDao.class).listCustomerDynamics(inputDynamics, (page-1)*pageSize, pageSize);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return dynamics;
    }
}
